#ifndef CVX_CAPTURE_H
#define CVX_CAPTURE_H 1

#include "cvxImage.h"
#include <vector>


#define CVX_CAPTURE_60PI_PFS 29.9700299     //fps of 60i in canon xf105

// enum
// {
// //	CVX_CAP_PROP_SKIP_MSEC    =0,
// //	CVX_CAP_PROP_POS_FRAMES   =1,
// // CV_CAP_PROP_POS_AVI_RATIO  =2,
// // CV_CAP_PROP_FRAME_WIDTH    =3,
// // CV_CAP_PROP_FRAME_HEIGHT   =4,
// //	CVX_CAP_PROP_FPS          =5
// };

class  CvxCapture
{
public:
	CvxCapture();
	virtual ~CvxCapture();
	
	virtual IplImage *GetNextFrame() = 0;
	CvSize GetImageSize(void){return m_size;}

protected:
	double m_currentTime;
	int    m_step;
	CvSize m_size;
};


/************************************************************************/
/* 
	CvxFileCapture
*/
/************************************************************************/

enum
{
	//CVX_FILE_CAP_PROP_FPS     =0,
	CVX_FILE_CAP_PROP_WIDTH   =1,
	CVX_FILE_CAP_PROP_HEIGHT  =2,
//	CVX_FILE_CAP_PROP_FORWARD_FRAMRS =3,             //forward some frames as current fps
	CVX_FILE_CAP_FLIP         =4
};

//capture from file
class CvxFileCapture: public CvxCapture
{
public:
	CvxFileCapture(CvCapture *cp, int step);
	~CvxFileCapture();

	virtual int SetProperty(int property_id, double value );
	virtual double GetProperty(int property_id );
	virtual IplImage *GetNextFrame();
	IplImage *GetIdxFrame(int idx);

private:
	CvCapture *m_capture;
	int        m_flipMode;
	int m_curFrameIdx;

	IplImage  *m_currentFrame;            //two frame swap to avoid memory leak
	IplImage  *m_deleteFrame;	
};

//capture from image sequence
class ImageSequenceCapture :public CvxCapture
{
public:
	ImageSequenceCapture();
	//path likes "save_image\\15_9\\bottom\\960\\*.png"
	ImageSequenceCapture(const string &path, int iscolor);
	~ImageSequenceCapture();

	virtual IplImage *GetNextFrame();
	void push_back(IplImage *img);
	void reset(void){m_currentIdx = 0;}
	int size(void) {return m_imgVec.size();}

public:
	vector<IplImage *> m_imgVec;
private:
	int m_currentIdx;
};

//capture from frame numbers
class CvxArbitraryCapture: public CvxCapture
{
public:
	CvxArbitraryCapture(CvCapture *cap);
	virtual ~CvxArbitraryCapture();

	virtual IplImage *GetNextFrame();
	IplImage *GetFrame(unsigned int frameNum);
	unsigned int maxFrame(void){return m_maxFrames;}

private:
	CvCapture *m_cap;
	unsigned int m_maxFrames;          //0 based

};




#endif